const button = $('.button button')
const leftul = $('.daikuan-bt')
const daikuan = $('.daikuan')
const sider = $('.fixed-sider')
const backicon = $('.sidericon-4')
const list= $('.daikuan3 .list-1')


function form1(){
    button.on('click', function () {
        let name = $('.input-form input[name="name"]').val()
        let phone = $('.input-form input[name="phone"]').val()
        let money = $('.input-form input[name="money"]').val()
        let test = $('.input-form input[name="test"]').val()
        let sex = $('.input-form input[name="sex"]:checked').val()
        const data = {
            'name':name,
            'call':phone,
            'amount':money,
            'sex':sex,
            'number':test
        }
        $.post('http://123.56.251.69:1006/index.php/api/auth/application/',data).then(
            function (data) {
                console.log(data)
            }
        )
    })
}

function daikuan1() {
    daikuan.on('click', function (event) {
        const name = event.target.innerText
        const changelist = $(event.target).parents('.daikuan').find('.list-1')
        $.ajax({
            url:'http://123.56.251.69:1006/index.php/api/auth/raiders',
            success:function (ret) {
                const res = ret.data[name]
                for (let i = 0;i< res.length;i++){
                    const spanlist = changelist[i].getElementsByTagName('span')
                    spanlist[0].innerText = res[i]['problem']
                    spanlist[1].innerText = res[i]['details']
                }
            }
        })
    })
}

function leftullist() {
    leftul.on('click','li',function (event) {
        var target = $(event.target);
        var targetlist = target.parent().find('li')

        $.each(targetlist,function (i,n) {
            $(n).removeClass('active')
        })
        target.addClass("active");
    })
}

function sidertoggle() {
    if(window.scrollY > 1500){
        sider.show('slow')
    }
    else {
        sider.hide('slow')
    }
}

function siderback() {
    backicon.on('click', function () {
        window.scrollTo(0,0)
    })
}

function daikuan3() {
    $.ajax({
        url: 'http://123.56.251.69:1006/index.php/api/auth/consultant',
        success: function (ret) {
            for (let i = 0; i < ret.data.length; i++) {
                $(list[i]).find('.daikuan3-card-name').text(ret.data[i]['name'])
                $(list[i]).find('.daikuan3-card-title').text(ret.data[i]['post'])
                $(list[i]).find('.daikuan3-card-phone').text(ret.data[i]['phone'])
                $(list[i]).find('.daikuan3-card-years').text(ret.data[i]['experience'])
                $(list[i]).find('.daikuan3-card-vol').text(ret.data[i]['volume'])
                $(list[i]).find('.daikuan3-card-task').text(ret.data[i]['task'])
            }
        }
    })
}

function play(){
    var index = 0
   setInterval(function () {
        if (index < 2){
            index++
            var leftoffset = 0-index * 268
            $('.company-list').css({'left':leftoffset+ 'px'})
        }
        else {
            index = 0
            $('.company-list').css({'left':0})
        }
    },3000)
}

export {form1, leftullist, sidertoggle, siderback, daikuan3, play, daikuan1}